package com.boyadegroot.divelog.models;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

public class DiveSite implements Parcelable, Comparable<DiveSite> {

    private static final String TAG = DiveSite.class.getName();

    private long mId;
    private String mName;
    private DiveLocation mLocation;

    public DiveSite() {}

    public DiveSite(long id, String name, DiveLocation location) {
        this.setId(id);
        this.setName(name);
        this.setLocation(location);
    }

    public long getId() {
        return mId;
    }

    public void setId(long id) {
        this.mId = id;
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        this.mName = name;
    }
    
    public DiveLocation getLocation() {
        return mLocation;
    }

    public void setLocation(DiveLocation location) {
        this.mLocation = location;
    }

    @Override
    public int compareTo(@NonNull DiveSite another) {
        return this.mName.compareTo(another.mName);
    }

    @Override
    public String toString() {
        return getName();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mId);
        dest.writeString(mName);
        dest.writeParcelable(mLocation, flags);
    }

    public static final Parcelable.Creator<DiveSite> CREATOR = new Parcelable.Creator<DiveSite>() {

        public DiveSite createFromParcel(Parcel in) {
            return new DiveSite(in);
        }

        public DiveSite[] newArray(int size) {
            return new DiveSite[size];
        }
    };

    private DiveSite(Parcel in) {
        mId = in.readLong();
        mName = in.readString();
        mLocation = in.readParcelable(DiveLocation.class.getClassLoader());
    }
}
